using System;
using System.Configuration;
using System.Data.SqlClient;
using System.Net.Mail;
using CCS;

namespace CCSService_WebRole
{
    /// <summary>
    /// Summary description for SendMail.
    /// </summary>
    public class SendMail
    {
        //constructor
        public SendMail() { }

        /// <summary>
        /// Send an email to the user with their license information
        /// </summary>
        /// <param name="invoice">The invoice for the transaction</param>
        /// <param name="authLicense">The product key generated by the system.</param>
        public void SendMailApprovedLicense(string invoice, string authLicense)
        {
            PaymentCustInfo paymentCustInfo = Procedures.SendMailApprovedLicense(StorageClientHelper.GetTableStorage(), StorageClientHelper.GetAccountInfo(), invoice);
            if (paymentCustInfo != null)
            {
                string body;
                string to = paymentCustInfo.Email;
                string subject = "Your product has been activated.";

                body = "<table width=\"500\"><tr><td>";
                body += "Dear " + paymentCustInfo.FirstName + ",<br><br><br>";
                body += "Thank you for activating your product.  Please make a note of the following information ";
                body += "for future reference:<br><br>";
                body += "</td></tr>";
                body += "<tr><td width=\"500\">";
                body += "Product Key: " + invoice + " ";
                body += "<br><br>";
                body += "</td></tr>";
                body += "<tr><td>";
                body += "Thank you,<Br>";
                body += Properties.Settings.Default.EmailFromName + "<br><br>";
                body += Properties.Settings.Default.FromEmailAddress;
                body += "</td></tr>";
                body += "</table>";

                try
                {
                    Send(subject, body, to);
                }
                catch
                {
                    //fail gracefully if the mail doesn't send
                }
            }

        }



        public void Send(string subject, string body, string to)
        {
            SmtpClient mailClient = new SmtpClient(Properties.Settings.Default.SMTP);
            MailAddress addressFrom = new MailAddress(Properties.Settings.Default.FromEmailAddress);
            MailAddress addressTo = new MailAddress(to);

        }


    }
}
